﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;

namespace DiskUsage
{
    class DirectoryInfoPresentation : DirectoryPresentationBase
    {
        DirectoryInfo m_directoryInfo;

        public DirectoryInfoPresentation(DirectoryInfo directoryInfo)
        {
            Contract.Ensures(directoryInfo != null);
            m_directoryInfo = directoryInfo;
        }

        public override string Name
        {
            get { return m_directoryInfo.Name; }
        }

        public override string Icon
        {
            get { return "Resources/folder.png"; }
        }

        public override string SmallIcon
        {
            get { return "Resources/folder.png"; }
        }

        public override DirectoryInfo DirectoryInfo
        {
            get { return m_directoryInfo; }
        }

        protected override List<DirectoryPresentationBase> PopulateChildren()
        {
            var children = new List<DirectoryPresentationBase>();
            Array.ForEach<DirectoryInfo>(m_directoryInfo.GetDirectories(),
                a => children.Add(new DirectoryInfoPresentation(a)));
            return children;
        }

        public override bool IsParentOf(DirectoryInfo dir)
        {
            if (dir == null || m_directoryInfo == null) return false;
            return dir.FullName.StartsWith(m_directoryInfo.FullName);
        }
    }
}
